Skip to content

Conversation

@habrahamsson-skanetrafiken
Copy link
Contributor

@habrahamsson-skanetrafiken habrahamsson-skanetrafiken commented Sep 9, 2025

Summary

This is mostly a refactor, but also fixes a bug in the filtering.

We've got an upcoming feature where we will want to use the TransitDataProviderFilter in a few new places. Currently the api of the filter interface is a bit convoluted since the caller has to decide whether to enable parts of the filtering depending on a complex set of circumstances, this causes tight coupling between the caller and TransitDataProviderFilter and makes it easy to make a mistake when using the TransitDataProviderFilter.

This PR changes the api of TransitDataProviderFilter so that the caller has to do the correct thing and first provide a TripPattern and then a TripTimes object.

By switching to this new api in the tests I also found a bug that is fixed.

I also found another bug that will be difficult to fix without some heavier rewriting of the filtering logic. I left it unfixed and made an @Ignored unit test to illustrate the problem.

Unit tests

The tests for TransitDatProviderFilter are updated to use both a TripPattern and a TripTimes object instead of testing the pattern and tripTimes filtering in isolation. This reflects how the filter class is actually used.

Documentation

I added some javadoc to undocumented methods.

Bumping the serialization version id

Nope

@habrahamsson-skanetrafiken habrahamsson-skanetrafiken requested a review from a team as a code owner September 9, 2025 14:14
@codecov
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

❌ Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 72.11%. Comparing base (3ec87bc) to head (83886da).
⚠️ Report is 45 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...equest/RaptorRoutingRequestTransitDataCreator.java 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             dev-2.x    #6850   +/-   ##
==========================================
  Coverage      72.10%   72.11%           
- Complexity     19670    19675    +5     
==========================================
  Files           2125     2125           
  Lines          79531    79529    -2     
  Branches        8051     8051           
==========================================
+ Hits           57348    57352    +4     
+ Misses         19346    19341    -5     
+ Partials        2837     2836    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

)
);

assertTrue(filter.tripTimesPredicate(tripTimesMatchingSubModeMatchingAgency, true));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't work in practice in the previous code since the filter would have returned false at the filter.tripPatternPredicate(p) check.

@habrahamsson-skanetrafiken habrahamsson-skanetrafiken added the +Skip Changelog This is not a relevant change for a product owner since last release. label Sep 9, 2025
@t2gran t2gran added this to the 2.9 (next release) milestone Sep 10, 2025
@habrahamsson-skanetrafiken habrahamsson-skanetrafiken changed the title Change api in TransitDataProviderFilter Changes to TransitDataProviderFilter Sep 11, 2025
Copy link
Member

@leonardehrenfried leonardehrenfried left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a bit of studying I think I understand this now but since it's a very delicate piece of code, I would like to get on a video call where you explain this once more in person.

Copy link
Member

@leonardehrenfried leonardehrenfried left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a call with @habrahamsson-skanetrafiken where we went through these changes. It's difficult to reason about all of this but after looking at it together I'm satisfied that this improves the code and doesn't introduce new bugs.

Copy link
Member

@t2gran t2gran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks good, just a few minor naming things.

if (filter.matchTripPattern(tripPatternForDate.getTripPattern().getPattern())) {
return true;
if (filter.matchTripPattern(tripPattern)) {
var withFilters = hasSubModeFilters && tripPattern.getContainsMultipleModes();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withFilters should probably have a better name. What about applyTripTimesFilters ? This apply to the tripTimesPredicate method argument as well.

return true;
if (filter.matchTripPattern(tripPattern)) {
var withFilters = hasSubModeFilters && tripPattern.getContainsMultipleModes();
return tripTimes -> this.tripTimesPredicate(tripTimes, withFilters);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return tripTimes -> this.tripTimesPredicate(tripTimes, withFilters);
return tripTimes ->tripTimesPredicate(tripTimes, withFilters);

Avoid using this. unless it is needed.


@Override
public boolean tripTimesPredicate(TripTimes tripTimes, boolean withFilters) {
private boolean tripTimesPredicate(TripTimes tripTimes, boolean withFilters) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming: withFilters see above

@Override
public boolean tripPatternPredicate(TripPatternForDate tripPatternForDate) {
@Nullable
public Predicate<TripTimes> getTripFilter(TripPattern tripPattern) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming this to createTripFilter

@leonardehrenfried
Copy link
Member

You have to remove unused imports.

@habrahamsson-skanetrafiken habrahamsson-skanetrafiken merged commit c08d739 into opentripplanner:dev-2.x Oct 8, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

+Skip Changelog This is not a relevant change for a product owner since last release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants